package net.csdra.place.domain;

import net.csdra.basis.domain.CJpaRepository;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Query;

import java.sql.Timestamp;
import java.util.List;

/**
 * Created by msf on 2018/1/29.
 */
public interface ReservationPlaceRepository extends CJpaRepository<ReservationPlace, String> {

    @Query("select distinct * from ReservationPlace " +
            " where metaId=?1" +
            " and reservationState=?2" +
            " and (" +
            "     begin between  ?3 and ?4 " +
            "   or " +
            "     end between ?3 and ?4 " +
            "   )")
    Page<ReservationPlace> findPageByMetaIdAndStateAndBeginAndEnd(String metaId, String reservationState, Timestamp begin, Timestamp end, Pageable pageable);

    @Query("select distinct * from ReservationPlace " +
            " where metaId=?1" +
            " and reservationState=?2" +
            " and (" +
            "     begin between  ?3 and ?4 " +
            "   or " +
            "     end between ?3 and ?4 " +
            "   )")
    List<ReservationPlace> findAllByMetaIdAndStateAndBeginAndEnd(String metaId, String reservationState, Timestamp begin, Timestamp end);


    Page<ReservationPlace> findByMetaIdAndReservationStateAndCreateTimeBetween(String metaId, String reservationState, Timestamp begin, Timestamp end, Pageable pageable);

    List<ReservationPlace> findByMetaIdAndReservationStateAndCreateTimeBetween(String metaId, String reservationState, Timestamp begin, Timestamp end);

}
